package com.yf.ability.login.dingtalk.service.impl;

import com.yf.ability.login.dingtalk.config.DingTalkConfig;
import com.yf.ability.login.dingtalk.dto.response.DingUserRespDTO;
import com.yf.ability.login.dingtalk.service.DingLoginService;
import com.yf.ability.login.dingtalk.utils.DingUtils;
import com.yf.base.api.exception.ServiceException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 微信登录业务类
 * @author bool
 */
@Service
public class DingLoginServiceImpl implements DingLoginService {


    @Autowired
    private DingTalkConfig dingTalkConfig;


    @Override
    public DingUserRespDTO login(String code) {
        // 转换为登录结果
        try {
            DingUserRespDTO resp = DingUtils.snsInfo(dingTalkConfig.getAppKey(), dingTalkConfig.getAppSecret(), code);
            // 登录并返回
            return resp;
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("获取钉钉用户信息失败！");
        }
    }


}
